<template>
  <div class="compact-box">
    <div v-if="list.list && list.list.length>0">
      <el-table :data="list.list" style="width: 100%">
        <el-table-column
          prop="contractName"
          label="合同名称"
          width="220">
        </el-table-column>
        <el-table-column
          prop="userName"
          label="签约人"
          width="150">
        </el-table-column>
        <el-table-column
          label="合同状态"
          width="120">
          <template slot-scope="scope">
            {{scope.row.contractStatus | contractFormat}}
          </template>
        </el-table-column>
        <el-table-column
          label="签署时间"
          width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.signTime">{{scope.row.signTime | FormatDate('yyyy-MM-dd')}}</span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作">
          <template slot-scope="scope">
              <!--合同状态:0待确认,1确认,2确认失败,3合同关闭，4合同生效，5合同终止，6合同到期'-->
            <el-button
              size="mini"
              type="primary"
              @click="$router.push({path: '/sponsor/merchants/compact/add/'+scope.row.id})"
              v-if="(scope.row.contractStatus === '' || !scope.row.contractStatus)">拟定合同</el-button>
            <el-button
              size="mini"
              type="primary"
              @click="$router.push({path: '/sponsor/merchants/compact/edit/'+scope.row.id})"
              v-if="scope.row.contractStatus === 2">修改合同</el-button>
            <el-button
              size="mini"
              type="primary"
              @click="contractClose(scope.row)"
              v-if="scope.row.contractStatus === 0">关闭合同</el-button>
            <el-button
              size="mini"
              type="primary"
              @click="signing(scope.row.id)"
              v-if="scope.row.contractStatus === 1">签署合同</el-button>
            <p v-if="scope.row.contractStatus === 3">合同已被关闭</p>
            <el-button
            type="primary"
            size="mini"
            @click="$router.push({path: '/sponsor/merchants/compact/show/'+scope.row.id})"
            v-if="scope.row.contractStatus === 4
              || scope.row.contractStatus === 5
              || scope.row.contractStatus === 6
              || scope.row.contractStatus === 1
              || scope.row.contractStatus === 0
              ">查看合同</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-bind="getPaginationProps(list)"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        >
      </el-pagination>
    </div>
    <e-placeholder v-else text="暂时没有合同哦" src="/static/images/no_match.png"></e-placeholder>
  </div>
</template>
<script>
  import { mapGetters } from 'vuex'
  import api from 'api/merchants'
  import { pagingList } from 'utils/mixins'
  export default{
    mixins: [pagingList],
    computed: {
      ...mapGetters({
        list: 'compact_merchants_list'
      })
    },
    components: {
      mapGetters
    },
    data () {
      return {
        query: this.getQuery()
      }
    },
    methods: {
      fetch (query) { // 初始化获取数据， 分页
        query.merId = this.$route.params.id
        // query.merId = 22
        this.$store.dispatch('compact_merchants_list', query)
      },
      signing (id) {
        api.signing_contract({
          contractDetailsId: id,
          return_url: location.origin + '/sponsor/merchants/compact/success?contractId=' + id
        }, {contexts: this, successMsg: 'none'}).then(res => {
          window.location.href = res.data
        })
      },
      contractClose (row) {
        this.$confirm('确认关闭改合同？',
          '提示'
        ).then(() => {
          api.contract_close({
            contractDetailsId: row.id
          }, {context: this, successMsg: 'none'}).then(res => {
            row.contractStatus = 3
          })
        })
      }
    }
  }
</script>
<style lang="scss">
  .compact-box{
    margin:35px 60px;
    .el-table thead th{
      background: #f5f5f5;
      font-weight: 500;
    }
    .el-table tbody td{
      height:120px;
    }
    .el-table tbody td:first-of-type{
      font-weight: 700;
    }
  }

</style>
